from django.contrib.auth.models import User
from django_summernote.admin import SummernoteModelAdmin
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from article import admin
from article.models import ArticlePost, ArticleColumn
from comment.models import Comment
from userprofile.models import Profile


class PostAdmin(SummernoteModelAdmin):
    summernote_fields = ('content')
    list_display = ['article_id', 'title', 'created_time']
    search_fields = ['created_time']


class CommentAdmin(admin.ModelAmin):
    list_display = ['username', 'body', 'title']
    search_fileds = ['title']


class ProfileInline(admin.StackedInline):
    model = Profile
    can_delete = False
    verbose_name_plural = 'UserProfile'


# 将 Profile 关联到 User 中
class UserAdmin(BaseUserAdmin):
    inlines = (ProfileInline,)


admin.site.register(Comment)
# 注册ArticlePost到admin中
admin.site.register(ArticlePost)
# 注册文章栏目
admin.site.register(ArticleColumn)
# 重新注册 User
admin.site.unregister(User)
admin.site.register(User, UserAdmin)
